package com.example.educationsystem.controller;

import com.example.educationsystem.pojo.User;
import com.example.educationsystem.service.UserService;
import com.example.educationsystem.utils.LoginVo;
import com.example.educationsystem.utils.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;
import java.util.List;

@Slf4j
@Controller
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @ResponseBody
    @GetMapping("/user/all")
    public String list(){
        List<User> uSers = userService.getUSers();
        String s = uSers.toString();
        return s;
    }

    //测试
    @ResponseBody
    @GetMapping("/user/all1")
    public  String getall(){
        return "帅";
    }


//    验证登录
    @GetMapping("/user/login")
    public ResultVO  login(String username,String password){
        ResultVO resultVO = userService.login(username, password);
        return resultVO;
    }

    //通过家庭号查询家庭内所有成员
    @GetMapping("user/family")
    public List<User> allfmaily(String userfmailyid){
        Integer id =Integer.valueOf(userfmailyid);
        List<User> userByUserFamily = userService.getUserByUserFamily(id);
//        String s = userByUserFamily.toString();
        return userByUserFamily;
    }


    @GetMapping("user/update")
    public String updateuser(String userId,String userCall,String userName,String userAge){
        Integer userId1=Integer.valueOf(userId);
        Integer useAge1=Integer.valueOf(userAge);
        int i = userService.updateuser(userId1, userCall, userName, useAge1);
        System.out.println("更新结构++++++++++++++++++++++++++++++++++++++++++"+i);
        if(i==0){
            return "更新失败";
        }else{
            return "成功";
        }
    }

    @GetMapping("user/delete")
    public String deleteuser(String userId){
        Integer userId1=Integer.valueOf(userId);
        int i = userService.deleteuser(userId1);
        if(i==0){
            return "删除失败";
        }else{
            return "成功";
        }
    }

//    @RequestMapping(value="student/addStudent",method = RequestMethod.POST)
//    @ResponseBody
//    public String addStudent(HttpServletRequest req, Model model) throws IOException {
//        //图片上传到服务器
//        CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(
//                req.getSession().getServletContext());
//        commonsMultipartResolver.setDefaultEncoding("utf-8");
//        MultipartHttpServletRequest multipartRequest = commonsMultipartResolver
//                .resolveMultipart(req);
//        MultipartFile multipartFile = multipartRequest.getFile("imgFile");
//        //获取绝对路径 并在指定相应目录创建File对象
//        String contextPath = req.getSession().getServletContext().getRealPath("/");
//        String fileName = "xxx.jpg";
//        File imgFile = new File(contextPath+"/static/images/"+fileName);
//        //上传文件
//        multipartFile.transferTo(imgFile);
//
//        return "要跳转的路径";
//    }




}
